<?php
class Message extends Controller {
	var $table = '`message`';
	function Controller() {
		parent::Controller();
	}

	function index() {
	}

	function show() {
		$this->load->model("Message_model","mMessage");
		$result = $this->mMessage->show_message();
		$data['header'] = $this->mMessage->retrive_header();
		$data['messages'] = $result->result_array();
		$this->load->view('message',$data);
	}
	
	function showm() {
		$this->db->where('`del`<>0');
		$this->db->order_by('`create` desc');
		$res = $this->db->get($this->table);
		var_dump($res->result_array());
	}
	
	function find($str) {
		$this->db->like('`content`',$str,'both');
		$res = $this->db->get('`message`');
		var_dump($res->result_array());
	}
	function create() {
		$this->load->model("Message_model","mMessage");
		$data=array('`userid`'=>1,'`operate`'=>'901');
		$this->mMessage->insert_message(2,'301','adsasddads');
		$this->db->insert($this->table,$data);
	}
	function dele($id) {
		$data = array('`del`'=>'1');
		$this->db->where('`id`',$id);
		$this->db->update($this->table,$data);
	}
	function download() {
		$this->load->dbutil();
		$this->load->model("Message_model","mMessage");
		$result = $this->mMessage->show_message();
		$data = $this->dbutil->csv_from_result($result,"\t");
		//$this->load->helper('file');
		$this->load->helper('download');
		force_download('ddd.xls', $data);
	}

	function insert() {
		$this->load->model("Message_model","mMessage");
		$userid = 1;
		$operate = 2;
		$content = 'A\B\C\D\E\F';
		$this->mMessage->insert_message($userid,$operate,$content);
	}
}